﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Oops.Xna.Framework
{
	/// <summary>
	/// An extension to the <see cref="System.TimeSpan" /> structure.
	/// </summary>
	public static class TimeSpanExtension
	{
		/// <summary>
		/// Restricts a value to be within a specified range.
		/// </summary>
		/// <param name="value">The value to clamp.</param>
		/// <param name="min">The minimum value.  If <paramref name="value"/> is less than <paramref name="min"/>, <paramref name="min"/> is returned.</param>
		/// <param name="max">The maximum value.  If <paramref name="value"/> is greater than <paramref name="max"/>, <paramref name="max"/> is returned.</param>
		/// <returns>The clamped value.</returns>
		public static TimeSpan Clamp(TimeSpan value, TimeSpan min, TimeSpan max)
		{
			return TimeSpan.FromTicks(Math.Max(Math.Min(value.Ticks, max.Ticks), min.Ticks));
		}
	}
}
